const Koa = require("koa");
const router = require("./src/router");
const static = require("koa-static");
const bodyParser = require("koa-body-parser");
const Logger = require("./src/middleware/Logger");
const ErrorHandle = require("./src/middleware/ErrorHandle");
const AuthGuard = require("./src/middleware/AuthGuard");
const cors = require("koa-cors");
const port = 3000;
function bootstrap() {
  const app = new Koa();
  app.use(
    cors({
      origin: true,
      credentials: true,
      allowMethods: ["GET", "POST", "DELETE", "PUT", "OPTION"],
      allowHeaders: ["Content-Type", "Authorization", "Accept", "token"]
    })
  );
  app.use(bodyParser());
  app.use(ErrorHandle);
  app.use(Logger);
  app.use(AuthGuard);
  app.use(router.routes(), router.allowedMethods());
  app.use(static("./static"));
  app.use(ctx => {
    ctx.redirect("/views/404.html");
  });
  app.listen(port, () => {
    console.log(`server is running on port ${port}...`);
  });
}

bootstrap();
